<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <title>报告</title>
    <base href="<%=basePath %>"/>
    <link rel="stylesheet" href="assets/css/bootstrap.css"/>
    <%--<link rel="stylesheet" href="assets/layui/css/layui.css">--%>
    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/bootstrap.min.js"></script>
    <script src="assets/js/jquery.validator.min.js"></script>
    <%--<script src="assets/layui/layui.all.js"></script>--%>

</head>
<div class="container" id="comboChoiceDiv">
    <div class="col-lg-10 col-lg-offset-1">
        <div>
            <table class="table table-hover table-bordered<%--table table-hover--%> <%--table table-border table-bordered table-hover table-bg table-sort--%>">
                <thead>
                <tr class="text-c">
                    <th width="80" style="text-align: center">项目名</th>
                    <th width="100" style="text-align: center">所属科室</th>
                    <th width="100" style="text-align: center">价格</th>
                    <th width="100" style="text-align: center">状态</th>
                    <th width="100" style="text-align: center">操作</th>
                </tr>
                </thead>
                <tbody style="text-align: center" id="itemTbody">
                <tr class="text-c">
                    <td colspan="5">
                        加载中。。。
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
        <div id="page" style="float: right">
            总共1页，当前第1页，一页5行，总共0行。
            <a class="btn-sm btn-primary" onclick="comboSelect(1)">上一页</a>
            <a class="btn-sm btn-primary" onclick="comboSelect(1)">下一页</a>
        </div>
    </div>
</div>

</div>
<script>

    $(document).ready(function () {
        getReportItem(1);
    });

    function getReportItem(pageNum) {
        if (pageNum > 0) {
            $.post('report/getReportItem.action',
                {"pageNum":pageNum},
                function (report) {
                    if (report.items.length == 0) {
                        $('#itemTbody').html(null);
                        $('#itemTbody').append(
                            "<tr>" +
                            "<td colspan='5'>没有符合条件的数据</td>" +
                            "</tr>"
                        );
                    } else {
                        $('#itemTbody').html(null);
                        report.items.forEach(function (v) {
                            $('#itemTbody').append(
                                "<tr>" +
                                // "<td><input name='1' type='checkbox' value='0'></td>" +
                                "<td>" + v.itemName + "</td>" +
                                "<td>" + v.desk.deskName + "</td>" +
                                "<td>" + v.itemMoney + "</td>" +
                                "<td>" + v.stateName + "</td>" +
                                "<td>" +
                                "<a class='btn-primary btn-sm' data-toggle='modal' data-target='#modal' onclick='details(" + v.comboId + ")'>详情</a> " +
                                "<a class='btn-primary btn-sm' onclick='choiceCombo(" + v.comboId + ")'>选择</a> " +
                                "</td>" +
                                "</tr>"
                            )
                        });
                    }
                }
            )
        }
    }

    function comboSelect(pageNum) {
        if (pageNum > 0) {
            $.post('combo/getCombos.action?pageNum=' + pageNum,
                $('#selectComdo').serialize(),
                function (combos) {
                    if (combos.list.length == 0) {
                        $('#comboTbody').html(null);
                        $('#comboTbody').append(
                            "<tr>" +
                            "<td colspan='5'>没有符合条件的数据</td>" +
                            "</tr>"
                        );
                    } else {
                        $('#comboTbody').html(null);
                        combos.list.forEach(function (v) {
                            $('#comboTbody').append(
                                "<tr>" +
                                // "<td><input name='1' type='checkbox' value='0'></td>" +
                                "<td>" + v.comboName + "</td>" +
                                "<td>" + v.comboMoney + "</td>" +
                                "<td>" + v.beginTime + "</td>" +
                                "<td>" + v.finishTime + "</td>" +
                                "<td>" +
                                "<a class='btn-primary btn-sm' data-toggle='modal' data-target='#modal' onclick='details(" + v.comboId + ")'>详情</a> " +
                                "<a class='btn-primary btn-sm' onclick='choiceCombo(" + v.comboId + ")'>选择</a> " +
                                "</td>" +
                                "</tr>"
                            )
                        });
                        $('#page').html(null);
                        $('#page').append("总共" + combos.pages + "页，当前第" + combos.pageNum + "页，一页" + combos.pageSize + "行，总共" + combos.total + "行。");
                        $('#page').append("<a class='btn-sm btn-primary' onclick='comboSelect(" + combos.prePage + ")'>上一页</a> ");
                        $('#page').append("<a class='btn-sm btn-primary' onclick='comboSelect(" + combos.nextPage + ")'>下一页</a>");

                    }
                }
            )
        }
    }

    //查询科室列表(里包含项目列表)
    function getDesks() {
        $.post('desk/getDesk.action',
            function (desks) {
                console.log(desks);
                var list = "<ul>";
                desks.forEach(function (v1) {
                    list += "<li>" + v1.deskName;
                    if (v1.items.length>0){
                        list += "<ul>";
                        v1.items.forEach(function (v2) {
                            list += "<li>" +
                                    "<input type='checkbox' id='itemId"+v2.itemId+"' value='itemId"+v2.itemId+"' type='checkbox'>"+
                                    "<label for='itemId"+v2.itemId+"'>"+v2.itemName+"</label>"+
                                  "</li>";
                        });
                        list += "</ul>";
                    }
                });
                list += "</ul>";
                $('#itemList').append(list);
                $('#itemList').append(
                    "<a class='btn-primary btn-sm'>添加套餐</a>"
                );
            }
        )
    }

</script>
</body>
</html>